
<?php

$cn=new ChuyenNganh();
$dscn=$cn->ds();
$hv=new HocVi();
$dshv=$hv->ds();
$tt=new TinhTrangGV();
$dstt=$tt->ds();
$cv=new ChucVu();
$dscv=$cv->ds();
$gt= new GioiTinh();
$dsgt=$gt->ds();
$magv=0;

if (isset($_GET['id'])){

	$magv=$_GET['id'];
	
}

$gv= new GiangVien();

$gv->getInfo($magv);

if ($_SERVER['REQUEST_METHOD']=='POST'){
	
		$ds=$_POST['dschucvu'];

				$index=0;

				$dsgvcv=array();

				foreach($ds as $key){
					$pos=new ChucVu();
					$pos->getInfo($key);
					$dsgvcv[$index]=$pos;
					$index++;
				}

					$gv->setTen($_POST['txtten']);
					$gv->setNgaySinh(NgayThang::dinhDangNhap($_POST['txtngaysinh']));
					$gv->setEmail($_POST['txtmail']);
					$gv->setTel($_POST['txttel']);
					$gv->setNamCongTac($_POST['txtnamct']);
					$cn->getInfo($_POST['slCN']);
					$gv->setChuyenNganh($cn);
					$gv->setMobile($_POST['txtmobile']);
					$gv->setCmnd($_POST['txtcmnd']);
					$gt->getInfo($_POST['slGT']);
					$gv->setGioiTinh($gt);
					
					$gv->setDSChucVu($dsgvcv);
					
					$hv->getInfo($_POST['slHV']);
					$gv->setHocVi($hv);
					$tt->getInfo($_POST['slTTGV']);
					$gv->setTinhTrangGV($tt);
					$gv->setHinhAnh("");
					$gv->setHeSoPhanCong($_POST['txthesophancong']);
					$gv->setMatKhau("");
					$gv->capNhat();
					header('location:index.php');
	
	

}
?>
<div class="thongtin_giangvien">
<form action="" method="POST" name="frmGV" enctype="multipart/form-data">
<legend>FORM UPLOAD GIẢNG VIÊN</legend>
		<table cellpadding="0px" cellspacing="0px">
				<tr>
					<td>Mã giảng viên: </td>
					<td>
						<input type="text" name="txtmagv" id="text" value='<?php echo $gv->getMa(); ?>'  disabled ><br />
					</td>
				</tr>
				<tr>
					<td>Họ và tên: </td>
					<td>
						<input type="text" name="txtten" id="text" value='<?php echo $gv->getTen(); ?>' ><br />
					</td>
				</tr>
				<tr>
					<td>Giới tính</td>
					<td>
						<?php 
						$chongt=$gv->getGioiTinh()->getMa();
						echo Common::createSelect($dsgt,"slGT",$chongt);
						?>
					</td>
				</tr>
				<tr>
					<td>Ngày sinh: (d/m/y):</td>
					<td>
						<?php
							$ngay=NgayThang::dinhDangXuat($gv->getNgaySinh());
						?>
						<input type="text" name="txtngaysinh" id="text" value='<?php echo $ngay; ?>' ><br />
					</td>
				</tr>
				<tr>
					<td>CMND:</td>
					<td><input type="text" name="txtcmnd" id="text" class="textnhap" value='<?php echo $gv->getCmnd(); ?>'><br /></td>
				</tr>
				<tr>
					<td>Mobile:</td>
					<td><input type="text" name="txtmobile" id="text" class="textnhap" value='<?php echo $gv->getMobile(); ?>' ><br /></td>
				</tr>
				<tr>
					<td>Email:</td>
					<td>
						<input type="text" name="txtmail" id="text" value='<?php echo $gv->getEmail(); ?>' ><br />
					</td>
				</tr>
				<tr>
					<td>Tel:</td>
					<td><input type="text" name="txttel" id="text" value='<?php echo $gv->getTel(); ?>'><br /></td>
				</tr>
				<tr>
					<td>Năm công tác:</td>
					<td><input type="text" name="txtnamct" id="text" value='<?php echo $gv->getNamCongTac(); ?>' ><br /></td>
				</tr>
				<tr>
					<td>Chuyên Ngành</td>
					<td>
						<?php 
						$choncn=$gv->getChuyenNganh()->getMa();
						echo Common::createSelect($dscn,"slCN",$choncn);
						?>
					</td>
				</tr>
				<tr>
					<td>Chức vụ:</td>
					<td>
						<div id="dschucvu">
						<?php
							

								foreach ($dscv as $key){

									$flag=false;

									$str="<input type=\"checkbox\" name=\"dschucvu[]\" value=\"".$key->getMa()."\" ";

									foreach ($gv->getDSChucVu() as $key1){

										if ($key->getMa()==$key1->getMa()){
												$flag=true;
											 	$str.="checked > ".$key1->getTen()."<br/>";
											 	echo $str;
										} 

									}

									if (!$flag){
										echo "<input type=\"checkbox\" name=\"dschucvu[]\" value=\"".$key->getMa()."\" >".$key->getTen()."<br/>";
									}							

							}
							

						?>
						</div>
					</td>
				</tr>

					<td>Học Vị: </td>

					<td>
						<?php 
						$chonhv=$gv->getHocVi()->getMa();
						echo Common::createSelect($dshv,"slHV",$chonhv);
						?>
					</td>
				</tr>
				<tr>
					<td>Tình Trạng: </td>
					<td>
						<?php 
						$chontt=$gv->getTinhTrangGV()->getMa();
						echo Common::createSelect($dstt,"slTTGV",$chontt);
						?>
					</td>
				</tr>
				<tr>
					<td>Hình Ảnh: </td>
					<td><input type="file" name="fhinhanh" id="text" class="textnhap" ><br /></td>
				</tr>
				<tr>
					<td>Hệ số phân công:</td>
					<td><input type="text" name="txthesophancong" id="text" value='<?php echo $gv->getHeSoPhanCong(); ?>' ><br /></td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="submit" value="Sửa" id="btthem2">
					</td>
				</tr>			
</form>
</table>
</div>

